package com.hongdee.crm.weChat.service.impl;

import com.hongdee.crm.weChat.dao.ITCrmCarDao;
import com.hongdee.crm.weChat.service.ITCrmCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Liu XiaoLong
 * Date: 2017/10/23.
 * Remark:
 */
@Service
public class WechatTCrmCarServiceImpl implements ITCrmCarService{
    @Autowired
    private ITCrmCarDao itCrmCarDao;
    private String tableName = "t_crm_car";


    /**
     * @Name: 查找用户车辆
     * @Author: Liu XiaoLong
     * @Date: 2017/10/23 10:51
     * @Remark:
     */
    @Override
    public Map getCar(String uid,String carNo,String mobile) throws Exception {
        if(carNo.isEmpty() && mobile.isEmpty()){
            throw new Exception("查询条件填写不全！");

        }else {
            List params = new ArrayList();
            String sql = "SELECT vin FROM t_crm_car WHERE 1=1 ";
            if (!carNo.isEmpty()){
                sql += "AND plate_num = ? ";
                //sql += "limit 10";
                params.add(carNo);
            }
            if(!mobile.isEmpty()){
                sql += " AND owner_tel = ? ";
                params.add(mobile);
            }
            Map respMap = itCrmCarDao.info(sql,params.toArray());
            Map map = new HashMap();
            if(!respMap.get("vin").toString().isEmpty()){
                map.put("success",true);
            }
            else {
                map.put("success",false);
            }
            map.put("data",respMap);
            return map;
        }


    }
}
